#include "widget.h"
#include "ui_widget.h"
#include<QDateTime>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->dateTimeEdit->setDisplayFormat("yyyy/MM/dd HH:mm");
    ui->dateTimeEdit_2->setDisplayFormat("yyyy/MM/dd HH:mm");
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{

    //获取两个timeDate里面的时间
 QDateTime time1=ui->dateTimeEdit->dateTime();
  QDateTime time2=ui->dateTimeEdit_2->dateTime();
     long long int sed=time1.secsTo(time2);
       int hours=(sed/3600)%24;
       int days=(sed/3600)/24;
       //把计算结果放到label中
       ui->label->setText(QString("爱你已经持续了 ") + QString::number(days)
                          + QString(" 天零 ") + QString::number(hours) + QString(" 小时"));



}
